package com.lanou.myapp.comic.rankingcomic.contentrankingcomic;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.android.volley.toolbox.Volley;
import com.lanou.myapp.R;
import com.lanou.myapp.comic.themecomic.contentthemecomic.ContentThemeComicBeans;
import com.lanou.myapp.imageloader.GsonRequest;
import com.lanou.myapp.imageloader.VolleySingleton;
import com.squareup.picasso.Picasso;


/**
 * Created by dllo on 16/1/19.
 */
public class ContentrankComicActivity extends AppCompatActivity {
    private TextView tv_author, tv_tag1, tv_tag2, tv_tag3, tv_hotNum, tv_readNum, tv_status;
    private TextView tv_description;
    private TextView tv_reader_name, tv_reader_say;
    private TextView tv_reader2_name, tv_reader2_say;
    private ImageView imageView;
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_rank_comic_activity);
        imageView = (ImageView) findViewById(R.id.iv_content_rank_comic);
        tv_author = (TextView) findViewById(R.id.tv_author_content_rank_comic);
        tv_tag1 = (TextView) findViewById(R.id.tv_content_tag1_rank_comic);
        tv_tag2 = (TextView) findViewById(R.id.tv_content_tag2_rank_comic);
        tv_tag3 = (TextView) findViewById(R.id.tv_content_tag3_rank_comic);
        tv_hotNum = (TextView) findViewById(R.id.tv_content_hotNum_rank_comic);
        tv_readNum = (TextView) findViewById(R.id.tv_readNum_content_rank_comic);
        tv_status = (TextView) findViewById(R.id.tv_status_content_rank_comic);
        tv_description = (TextView) findViewById(R.id.tv_description_content_rank_comic);
        tv_reader_name = (TextView) findViewById(R.id.tv_content_reader_rank_comic);
        tv_reader_say = (TextView) findViewById(R.id.tv_reader_say_content_rank_comic);
        tv_reader2_name = (TextView) findViewById(R.id.tv_content_reader2_rank_comic);
        tv_reader2_say = (TextView) findViewById(R.id.tv_reader2_say_content_rank_comic);

        Intent intent = getIntent();
        Integer a = intent.getIntExtra("key", 0);
        String b = "http://v2.api.dmzj.com/comic/";
        String c = ".json";
        String url = b + a + c;

        GsonRequest<ContentRankComicBeans> request = new GsonRequest<ContentRankComicBeans>(url, ContentRankComicBeans.class, new Response.Listener<ContentRankComicBeans>() {
            @Override
            public void onResponse(ContentRankComicBeans response) {

                tv_author.setText(response.getAuthors().get(0).getTag_name());
                tv_tag1.setText(response.getTypes().get(0).getTag_name());
                if (response.getTypes().size() > 1) {
                    tv_tag2.setText(response.getTypes().get(1).getTag_name());
                }
                if (response.getTypes().size() > 2) {
                    tv_tag3.setText(response.getTypes().get(2).getTag_name());
                }
                tv_hotNum.setText(String.valueOf(response.getHot_num()));
                tv_readNum.setText(String.valueOf(response.getSubscribe_num()));
                tv_status.setText(response.getStatus().get(0).getTag_name());
                tv_description.setText(response.getDescription());
                tv_reader_name.setText(response.getComment().getLatest_comment().get(0).getNickname());
                tv_reader_say.setText(response.getComment().getLatest_comment().get(0).getContent());
                tv_reader2_name.setText(response.getComment().getLatest_comment().get(1).getNickname());
                tv_reader2_say.setText(response.getComment().getLatest_comment().get(1).getContent());


//                networkImageView.setDefaultImageResId(R.mipmap.v6_boy_unseletor_icon);
//                networkImageView.setErrorImageResId(R.mipmap.v5_icon_usercenter);
//                networkImageView.setImageUrl(response.getCover(), imageLoader);

                Picasso.with(context).load(response.getCover()).resize(250,300).into(imageView);

//                ImageLoader.ImageListener listener = ImageLoader.getImageListener(networkImageView, R.mipmap.v6_boy_unseletor_icon, R.mipmap.v6_boy_unseletor_icon);
//                VolleySingleton.getImageLoader().get(response.getCover(), listener, 400, 300);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });

        VolleySingleton.getInstance()._addRequest(request);
    }
}
